package wy.hanyufang.cn.socket.listener;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wy.hanyufang.cn.socket.SimpleChannelHandlerPool;

/**
 * @author ： wyhanyufang@163.com
 * @time ： 9:41 PM 2021/9/23
 */
public class ScannerLoginSocketListener implements ChannelFutureListener {
    private static final Logger logger = LoggerFactory.getLogger(ScannerLoginSocketListener.class);
    @Override
    public void operationComplete(ChannelFuture channelFuture) throws Exception {
        logger.info("完成：{}",channelFuture.channel().id());
        //将连接完成的channel ID发送给前端
        ChannelId channelId = channelFuture.channel().id();
        Channel channel = SimpleChannelHandlerPool.channels.find(channelId);
        if (channel != null){
            channel.writeAndFlush(channelId);
        }
    }
}
